package frontend.view;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class InsertFrame extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel menuPanel;
	private JPanel mainPanel;
	private InsertPanel insPanel;
	private JButton save;
	private JButton cancel;
	private static InsertFrame instance = null;

	private InsertFrame() {
		this.insPanel = new InsertPanel();
		mainPanel = new JPanel();
		mainPanel.setLayout(new BorderLayout());
		mainPanel.add(insPanel, BorderLayout.CENTER);

		Dimension dim = new Dimension(80, 30);
		save = new JButton("Save");
		cancel = new JButton("Cancel");
		save.setPreferredSize(dim);
		cancel.setPreferredSize(dim);

		menuPanel = new JPanel();
		menuPanel.setPreferredSize(dim);
		menuPanel.setLayout(new FlowLayout());
		menuPanel.add(save);
		menuPanel.add(cancel);
		mainPanel.add(menuPanel, BorderLayout.EAST);

		this.setContentPane(mainPanel);
		this.setBounds(300, 300, 500, 300);
		this.setResizable(false);
		this.setVisible(true);
		this.setLocationRelativeTo(null);
	}
	
	public void resetFields() {
		insPanel.getNameField().setText("");
		insPanel.getFirstNameField().setText("");
		insPanel.getMobileNrField().setText("");
		insPanel.getEmailField().setText("");
		insPanel.getFunctionField().setText("");
		insPanel.getUsernameField().setText("");
		insPanel.getPasswordField().setText("");
		insPanel.getRoleField().setSelectedIndex(0);;
	}

	public static synchronized InsertFrame getInstance() {
		if (instance == null) {
			instance = new InsertFrame();
		}
		return instance;
	}

	public static synchronized void reset() {
		instance = null;
	}

	public JButton getSave() {
		return save;
	}

	public void setSave(JButton save) {
		this.save = save;
	}

	public JButton getCancel() {
		return cancel;
	}

	public void setCancel(JButton cancel) {
		this.cancel = cancel;
	}

	public InsertPanel getInsPanel() {
		return insPanel;
	}

	public void setInsPanel(InsertPanel insPanel) {
		this.insPanel = insPanel;
	}

}
